package com.micro.turtle.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * Api 接口地址
 *
 * @author jason.lv
 * @since 2022/1/21 13:51
 */
@NoArgsConstructor
@AllArgsConstructor
public class Url {

    /**
     * Git Lab 地址
     */
    public volatile static String DOMAIN;
    /**
     * Git Lab Api
     */
    public volatile static String API;

    @Getter
    private String uri;

    public static Url create(String uri) {
        uri = DOMAIN + API + uri;
        return new Url(uri);
    }

    public Url group(Integer groupId) {
        uri = uri.replace(":group_id", String.valueOf(groupId));
        return this;
    }

    public Url project(Integer projectId) {
        uri = uri.replace(":project_id", String.valueOf(projectId));
        return this;
    }

    public Url pipeline(Integer pipelineId) {
        uri = uri.replace(":pipeline_id", String.valueOf(pipelineId));
        return this;
    }

    public Url job(Integer jobId) {
        uri = uri.replace(":job_id", String.valueOf(jobId));
        return this;
    }

    public static class GroupUri {

        // query: ?owned=true&search=microsf
        public final static String LIST = "/groups";

        // query: ?search=svc
        public final static String SUB_LIST = "/groups/:group_id/subgroups";
    }

    public static class ProjectUri {

        // query: ?owned=true&order_by=id&sort=asc&search=message
        public final static String LIST = "/groups/:group_id/projects";

        // query: ?owned=true&order_by=id&sort=asc&search=message
        public final static String DETAIL = "/projects/:project_id";
    }

    public static class PipelineUri {

        // query : ?order_by=id&sort=desc
        public final static String LIST = "/projects/:project_id/pipelines";

        // method : Post
        public final static String CREATE = "/projects/:project_id/pipeline?ref=develop";

        // method : Post
        public final static String RETRY = "/projects/:project_id/pipelines/:pipeline_id/retry";

        // method : Post
        public final static String CANCEL = "/projects/:project_id/pipelines/:pipeline_id/cancel";

        // method : Delete
        public final static String DELETE = "/projects/:project_id/pipelines/:pipeline_id";
    }

    public static class JobUri {

        // query : ?order_by=id&sort=asc
        public final static String LIST = "/projects/:project_id/pipelines/:pipeline_id/jobs";

        // query :
        public final static String DETAIL = "/projects/:project_id/jobs/:job_id";

        // method : Post
        public final static String PLAY = "/projects/:project_id/jobs/:job_id/play";

        // method : Post
        public final static String RETRY = "/projects/:project_id/jobs/:job_id/retry";

        // method : Post
        public final static String CANCEL = "/projects/:project_id/jobs/:job_id/cancel";

        // method : Post
        public final static String DELETE = "/projects/:project_id/jobs/:job_id/erase";
    }
}
